package com.headFirstModel.commandPattern.command;

import com.headFirstModel.commandPattern.action.CeilingFan;

public class CeilingFanMediumCommand implements Command{
    private CeilingFan ceilingFan;
    int prevSpeed; //追踪电扇之前的速度

    public CeilingFanMediumCommand(CeilingFan ceilingFan){
        this.ceilingFan=ceilingFan;
        prevSpeed=ceilingFan.getSpeed();
    }

    @Override
    public void execute() {
        prevSpeed=ceilingFan.getSpeed();
        ceilingFan.medium();
    }

    @Override
    public void undo() {
        if(prevSpeed==CeilingFan.HIGH){
            ceilingFan.high();
        }else
        if(prevSpeed==CeilingFan.MEDIUM){
            ceilingFan.medium();
        } else
        if(prevSpeed==CeilingFan.LOW){
            ceilingFan.low();
        }else{
            ceilingFan.off();
        }
    }
}
